/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.gad.ui;

import org.gad.model.CompositeStep;
import org.gad.model.Step;
import org.netbeans.api.visual.anchor.AnchorFactory;
import org.netbeans.api.visual.anchor.AnchorShape;
import org.netbeans.api.visual.router.RouterFactory;
import org.netbeans.api.visual.widget.ConnectionWidget;

/**
 *
 * @author Tomek
 */
public class SequenceStepWidget extends CompositeStepWidget
{

    private int _childCount = 0;
    private ConnectionWidget _lastConnection;

    public SequenceStepWidget(BoxScene scene, Step modelStep)
    {
        super(scene, modelStep);
        _clientArea.addChild(new DropAreaWidget(scene, true,
                (CompositeStep) _modelStep, _childCount++));
        
        
        ConnectionWidget edge = new ConnectionWidget (scene);
        edge.setSourceAnchor (AnchorFactory.createDirectionalAnchor(
                _headerVFlow, AnchorFactory.DirectionalAnchorKind.VERTICAL));
        edge.setTargetAnchor (AnchorFactory.createDirectionalAnchor(
                _bottomWidget, AnchorFactory.DirectionalAnchorKind.VERTICAL));
        edge.setTargetAnchorShape(AnchorShape.TRIANGLE_FILLED);
        //edge.setMaximumSize( new Dimension( 2,2));
        edge.setRouter (RouterFactory.createOrthogonalSearchRouter() );
        
        _lastConnection = edge;
        _scene.getConnectionLayer().addChild(edge);
        //this.addChild( edge );
    }

    @Override
    public void addInnerStep(StepWidgetBase step)
    {
        step._parent = this;
        _clientArea.addChild(new InnerStepWrapperWidget(_scene, step,
                false, (CompositeStep) _modelStep, _childCount++));
        
        _lastConnection.setTargetAnchor(AnchorFactory.createDirectionalAnchor(
                step, AnchorFactory.DirectionalAnchorKind.VERTICAL));
        
        ConnectionWidget edge = new ConnectionWidget (_scene);
        edge.setSourceAnchor (AnchorFactory.createFreeRectangularAnchor(
                step, true));
        edge.setTargetAnchor (AnchorFactory.createFreeRectangularAnchor(
                _bottomWidget, true));
        edge.setTargetAnchorShape(AnchorShape.TRIANGLE_FILLED);
        //edge.setMaximumSize( new Dimension( 2,2));
        edge.setRouter (RouterFactory.createOrthogonalSearchRouter() );
        
        _lastConnection = edge;
        _scene.getConnectionLayer().addChild(edge);
        //this.addChild( edge );
    }

    @Override
    public void removeInnerStep(StepWidgetBase step)
    {
        ((CompositeStep) _modelStep).RemoveStep(step._modelStep);
    }
}
